//
//  YSReadPageController.m
//  YSBookRead
//
//  Created by MOLBASE on 2018/11/7.
//  Copyright © 2018年 YangShen. All rights reserved.
//

#import "YSReadPageController.h"
#import "YSReaderSetting.h"
#import "YSStatusView.h"
#import "YSReadView.h"
#import "YSBookChapterContentModel.h"

@interface YSReadPageController ()

/// 背景图片
@property (nonatomic, weak) UIImageView *backImageView;
/// 顶部状态栏
@property (nonatomic, weak) UILabel *topStatusLabel;
/// 底部状态栏
@property (nonatomic, weak) YSStatusView *bottomStatusView;
/// 当前阅读View
@property (nonatomic, weak) YSReadView *readView;

@end

@implementation YSReadPageController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];

    // 添加子控件
    [self setupSubViews];
}

- (void)setupSubViews {

    UIImageView *backImageView = [[UIImageView alloc] initWithFrame:self.view.bounds];
    backImageView.image = [YSReaderSetting shareReaderSettings].themeImage;
    [self.view addSubview:backImageView];
    self.backImageView = backImageView;

    UILabel *topStatusLabel = [[UILabel alloc] init];
    topStatusLabel.lineBreakMode = NSLineBreakByTruncatingMiddle;
    topStatusLabel.textColor = [[YSReaderSetting shareReaderSettings] otherTextColor];
    topStatusLabel.font = [UIFont systemFontOfSize:12];
    topStatusLabel.frame = CGRectMake(kYSReaderXSpace, 0, self.view.frame.size.width - 2 * kYSReaderXSpace, kYSReaderYSpace);
    [self.view addSubview:topStatusLabel];
    self.topStatusLabel = topStatusLabel;

    YSStatusView *bottomStatusView = [[YSStatusView alloc] initWithFrame:CGRectMake(kYSReaderXSpace, self.view.frame.size.height - kYSReaderYSpace, self.view.frame.size.width - 2 * kYSReaderXSpace, kYSReaderYSpace)];
    bottomStatusView.backgroundColor = [UIColor clearColor];
    [self.view addSubview:bottomStatusView];
    self.bottomStatusView = bottomStatusView;

    YSReadView *readView = [[YSReadView alloc] init];
    self.readView = readView;
    readView.frame = YSReaderFrame();
    [self.view addSubview:readView];
    readView.backgroundColor = [UIColor clearColor];


    [self prepareData];
}

- (void)prepareData {
    self.topStatusLabel.text = self.chapterContentModel.chapterName;
    self.bottomStatusView.titleLabel.text = [NSString stringWithFormat:@"第%zi/%zi页",self.page+1,self.chapterContentModel.pageCount];
    self.readView.content = [self.chapterContentModel getStringWith:self.page];
}

@end

